import { _decorator,  UITransform, Vec2 } from 'cc';
import { StateDefine } from '../../Config';
import { Enemy_Skeleton } from './Enemy_Skeleton';
import { EnemyState } from '../EnemyState';
const { ccclass, property } = _decorator;

@ccclass('SkeletonAttackState')
export class SkeletonAttackState extends EnemyState {
    protected enemy:Enemy_Skeleton;
    constructor(name: StateDefine, _enemy: Enemy_Skeleton, anim: StateDefine) {
        super(name, _enemy, anim);
        this.enemy = _enemy;
    }
    onEnter() {
        super.onEnter();
        // this.enemy.ZeroVelocity()
        this.enemy.LastAttack = new Date().getTime();
    }
    onExit() {
        super.onExit();
        this.animation.node.getComponent(UITransform).anchorPoint = new Vec2(0.5,0.5)//偏移问题
    }
    update(deltaTime: number) {
        super.update(deltaTime);
        this.enemy.ZeroVelocity()
        if(this.triggerCalled){
            this.enemy.stateMgr.transit(StateDefine.SkeletonBattle);
        }
    }
    onDestory() { }

    canTransit(to: StateDefine): boolean {
        return true;
    }
}


